/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

package com.zog
{
	import com.pblabs.engine.PBE;
    import com.pblabs.engine.debug.Logger;
    import com.pblabs.engine.entity.EntityComponent;
    import com.pblabs.engine.entity.PropertyReference;
    import flash.geom.Point;
    
    public class RandomPoint extends EntityComponent
    {
        /**
         * min offset
         */
        public var min:Point = new Point();
        
        /**
         * max offset
         */
        public var max:Point = new Point();
        
        public var point:Point = new Point();
        public var pointProperty:PropertyReference = null;
        
        /**
         * This is the varying point to be used.
         */
        public function get randomPoint():Point
        {
            var newPoint:Point = point.clone();
            
            if(pointProperty)
            {
                newPoint = owner.getProperty(pointProperty) as Point;
            }

            var randX:Number = Math.random();
            var randY:Number = Math.random();
            var oneMinusRandX:Number = 1.0 - randX;
            var oneMinusRandY:Number = 1.0 - randY;
            var newX:Number = randX * max.x + oneMinusRandX * min.x;
            var newY:Number = randY * max.y + oneMinusRandY * min.y;
        
            newPoint.x += newX;
            newPoint.y += newY;
            
            return newPoint;
        }
        
        protected override function onAdd():void
        {
            super.onAdd();
        }
        
		protected override function onRemove():void
		{
			super.onRemove();
		}
    }
}